home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / liblight / light.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  2.1 KB  |  94 lines

  1. /*
  2.  * light.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * light.c,v 4.1 1994/08/09 07:57:05 explorer Exp
  17.  *
  18.  * light.c,v
  19.  * Revision 4.1  1994/08/09  07:57:05  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:04  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:35:01  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "light.h"
  30.  
  31. Light *
  32. LightCreate(light, meth, color)
  33. LightRef light;
  34. LightMethods *meth;
  35. Color *color;
  36. {
  37.     Light *ltmp;
  38.  
  39.     if (light == (LightRef)NULL || meth == (LightMethods *)NULL)
  40.         return (Light *)NULL;
  41.  
  42.     ltmp = (Light *)share_malloc(sizeof(Light));
  43.     ltmp->light = light;
  44.     ltmp->methods = meth;
  45.     ltmp->color = *color;
  46.     ltmp->next = (Light *)NULL;
  47.     ltmp->cache = (ShadowCache *)NULL;
  48.     ltmp->shadow = TRUE;
  49.     return ltmp;
  50. }
  51.  
  52. LightMethods *
  53. LightMethodsCreate()
  54. {
  55.     return (LightMethods *)share_calloc(1, sizeof(LightMethods));
  56. }
  57.  
  58. /*
  59.  * Compute light color.  Returns FALSE if in full shadow, TRUE otherwise.
  60.  * Computed light color is stored in 'color'.
  61.  */
  62. int
  63. LightIntens(lp, ray, dist, noshadow, color)
  64. Light *lp;
  65. Ray *ray;
  66. Float dist;
  67. int noshadow;
  68. Color *color;
  69. {
  70.     if (lp->methods->intens)
  71.         return (*lp->methods->intens)(lp->light, &lp->color,
  72.             lp->cache, ray, dist, noshadow || !lp->shadow, color);
  73.     RLerror(RL_ABORT, "Cannot compute light intensity!\n");
  74.     return FALSE;
  75. }
  76.  
  77. /*
  78.  * Calculate ray and distance from position to light.
  79.  */
  80. int
  81. LightDirection(lp, objpos, lray, dist)
  82. Light *lp;
  83. Vector *objpos, *lray;
  84. Float *dist;
  85. {
  86.     if (lp->methods->dir) {
  87.         (*lp->methods->dir)(lp->light, objpos, lray, dist);
  88.         return TRUE;
  89.     } else {
  90.         RLerror(RL_ABORT, "Cannot compute light direction!\n");
  91.         return FALSE;
  92.     }
  93. }
  94.